home *** CD-ROM | disk | FTP | other *** search
- '==========================================================
- '
- ' Module - BLOWUP.BAS
- '
- ' Module Prefix - None
- '
- ' Author - Peter J. Morris. TMS Ltd.
- '
- ' Date Written : #### Date - 16/11/94 Time - 03:11
- '
- ' Purpose -
- ' Support module for TMS blowup used for demonstration purposes only.
- ' The 'C' source for the DLL is normally to be distributed with this demo.
- ' TMS dudes/dudettes - this code may not be used without error handlers.
- '
- ' Revisions
- ' BY WHY AFFECTED
- ' Peter J. Morris. TMS Ltd. Original code.
- '
- '==========================================================
-
-
- Option Explicit
-
-
- ' General dummy variable - variant so that it can hold anything!
- Global g_vDummy As Variant
-
- ' Use to hold a window's dimensions typically.
- Type RECT
- Left As Integer
- Top As Integer
- Right As Integer
- Bottom As Integer
- End Type
-
- ' Holds information regarding a window's position on the desktop.
- Type WINDOWPOS
- hWnd As Integer
- HwndInsertAfter As Integer
- X As Integer
- Y As Integer
- CX As Integer
- CY As Integer
- Flags As Integer
- End Type
-
- ' Copy long pointer to WINDOWPOS structure functions/possibilities.
-
- ' Custom DLL function to copy one WINDOWPOS to another! Both are passed as
- ' pointers - trouble is that the second is a 'Long' in VB so we need a DLL
- ' to do this.
- ' ----------------------------------------------------------------
- ' COMMENT IN #1 IN MsgBlaster1_Message TO SEE THIS WORK (DEFAULT).
- ' ----------------------------------------------------------------
- Declare Function CopyWP1 Lib "DLL.DLL" Alias "nGetWindowPos" (t As WINDOWPOS, ByVal l As Long) As Integer
-
-
- ' This standard 'kernel' function would almost do and save us from
- ' having to write our own DLL function. We would declare it as follows.
- ' The 'problem' with this function is that it doesn't always copy 'n'
- ' bytes. It'll stop if it finds a NULL (a byte that contains the value
- ' 0) in the source string - bugger!
- ' -----------------------------------------------------------
- ' COMMENT IN #2 IN MsgBlaster1_Message TO SEE IT ALMOST WORK.
- ' -----------------------------------------------------------
- Declare Function CopyWP2 Lib "Kernel" Alias "lstrcpyn" (t As WINDOWPOS, ByVal l As Long, ByVal n As Integer) As Long
-
-
- ' However, this standard function does exist and DOES save us from having
- ' to write our own function. hmemcpy is 'in' Windows 3.1 and later and is
- ' used to copy one area of memory to another. Note that ALL memory is copied,
- ' i.e. a NULL byte is nothing special to hmemcpy.
- ' ------------------------------------------------------
- ' COMMENT IN #3 IN MsgBlaster1_Message TO SEE THIS WORK.
- ' ------------------------------------------------------
- Declare Sub CopyWP3 Lib "Kernel" Alias "hmemcpy" (t As WINDOWPOS, ByVal l As Long, ByVal n As Long)
-
-
- ' Windows' API procedures used throughout.
- Declare Function MoveTo Lib "GDI" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer) As Long
- Declare Function LineTo Lib "GDI" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer) As Integer
- Declare Function GetDC Lib "User" (ByVal hWnd As Integer) As Integer
- Declare Function ReleaseDC Lib "User" (ByVal hWnd As Integer, ByVal hDC As Integer) As Integer
- Declare Function SetROP2 Lib "GDI" (ByVal hDC As Integer, ByVal nDrawMode As Integer) As Integer
- Declare Function WinHelp Lib "User" (ByVal hWnd As Integer, ByVal lpHelpFile As String, ByVal nCommand As Integer, ByVal dwData As Long) As Integer
- Declare Sub GetWindowRect Lib "User" (ByVal hWnd As Integer, lpRect As RECT)
- Declare Sub DrawFocusRect Lib "User" (ByVal hDC As Integer, lpRect As RECT)
- Declare Sub InflateRect Lib "User" (lpRect As RECT, ByVal X As Integer, ByVal Y As Integer)
-
-
- ' Used to test 'Flags' member in WINDOWPOS struct passed into TMSExplodeForm as nFlags.
- Const SWP_NOACTIVATE = &H10
- Const SWP_NOMOVE = &H2
- Const SWP_NOSIZE = &H1
-
- Const R2_NOT = 6
-
- ' Used by the message blaster control.
- Global Const PREPROCESS = -1
- Global Const EATMESSAGE = 0
- Global Const POSTPROCESS = 1
- Global Const WM_WINDOWPOSCHANGING = &H46
-
- ' NUM_DELAY is used as a 'base' upper limit for a general delay loop counter.
- Const NUM_DELAY = 5000
-
- ' Number of seperate explosion states.
- Const NUM_STEPS = 10
-
- '==========================================================
- '
- ' Function - TMSExplodeForm
- '
- ' Author - Peter J. Morris. TMS Ltd.
- '
- ' Date Written: #### Date - 16/11/94 Time - 03:11
- '
- ' Purpose - See function purpose.
- '
- ' Revisions:
- ' BY WHY AFFECTED
- ' Peter J. Morris. TMS Ltd. Original code.
- '
- '
- ' INPUTS - frm -> Form to explode.
- ' tNewPos -> A RECT which is the window's new screen position.
- ' nFlags -> Flags member of the WINDOWPOS structure.
- '
- ' OUTPUTS - None, except a dazzling effect!
- '
- '==========================================================
- Sub TMSExplodeForm (frm As Form, tNewPos As RECT, ByVal nFlags As Integer)
- '==========================================================
- '
- ' Form: BLOWUP.BAS Procedure: TMSExplodeForm
- '
- ' Author - Peter J. Morris. TMS Ltd.
- ' Template fitted: #### Date - 16/11/94 Time - 03:11
- '
- ' Copyright and status if any: Copyright ⌐ TMS 1994,1995
- ' All rights reserved. Status @BLUE@TMS.DEMO@COLD
- '
- ' Purpose/Description In brief:
- '
- ' This is the routine that explodes the frm given in 'frm'. This routine is called from
- ' the message blaster 'call-back' event handler. It is passed a rectangle wihich is the
- ' exploding form's 'new' screen position, a flags variable explaining what is causing the
- ' explosion and of course the form to explode.
- '
- '=========================================================
-
- ' Set up general error handler
-
- 'On Error GoTo Error_TMSExplodeForm:
-
- ' ========== Code Starts.==========
-
- ' General loop counter.
- Dim nLoop As Integer
-
- ' Delay loop counter.
- Dim lDelayCount As Long
-
- ' The new width and height required.
- Dim nWindowWidth As Integer
- Dim nWindowHeight As Integer
-
- ' Window's current screen position.
- Dim tOldPos As RECT
-
- ' Hold 'device/display context' for entire desktop window.
- Dim hDCScreen As Integer
-
- ' Ignore stuff that shouldn't bother us - we don't want to explode all the time!
- If ((nFlags And SWP_NOMOVE) = SWP_NOMOVE) Or ((nFlags And SWP_NOSIZE) = SWP_NOSIZE) Or (nFlags = 0) Then Exit Sub
-
- ' Get current window size etc.
- GetWindowRect frm.hWnd, tOldPos
-
- ' Get new required height and width.
- nWindowWidth = tNewPos.Right - tNewPos.Left
- nWindowHeight = tNewPos.Bottom - tNewPos.Top
-
- ' Get a device context for the screen - this is so that
- ' we can draw anywhere on the screen.
- hDCScreen = GetDC(0)
-
- ' Set our drawing mode so that the pen draw with the inverse
- ' color used in the current pixel location. This is used to
- ' ensure that the lines drawn from the edge of the old rect
- ' to the edges of the new rect do destroy any of the background.
- g_vDummy = SetROP2(hDCScreen, R2_NOT)
-
- ' 'Grow' 'where it is' and 'where it will be' rectangles by a pel - makes
- ' drawing the initial rectangle around them look a little nicer.
- InflateRect tNewPos, 1, 1
- InflateRect tOldPos, 1, 1
-
- For nLoop = 0 To 1
-
- ' Draw a line from each corner of the 'where it is' rectangle to the
- ' each corner of the 'where it will be' rectangle. Once the lines are
- ' drawn, draw a box around each rectangle. After a short delay un-draw
- ' each box/line.
-
- ' Top left.
- g_vDummy = MoveTo(hDCScreen, tOldPos.Left, tOldPos.Top)
- g_vDummy = LineTo(hDCScreen, tNewPos.Left, tNewPos.Top)
-
- ' Top right.
- g_vDummy = MoveTo(hDCScreen, tOldPos.Right, tOldPos.Top)
- g_vDummy = LineTo(hDCScreen, tNewPos.Right, tNewPos.Top)
-
- ' Bottom right.
- g_vDummy = MoveTo(hDCScreen, tOldPos.Right, tOldPos.Bottom)
- g_vDummy = LineTo(hDCScreen, tNewPos.Right, tNewPos.Bottom)
-
- ' Bottom left.
- g_vDummy = MoveTo(hDCScreen, tOldPos.Left, tOldPos.Bottom)
- g_vDummy = LineTo(hDCScreen, tNewPos.Left, tNewPos.Bottom)
-
- ' Draw outlines on 'where it is' and 'where it will be' rectangles.
- DrawFocusRect hDCScreen, tNewPos
- DrawFocusRect hDCScreen, tOldPos
-
- ' Do the next bit - the delay - only if we've been through the loop
- ' once before, i.e. not if this is the 'un-draw everything' run as
- ' the delay is used to give us an adjustable 'pause' between drawing
- ' and undrawing, not exiting this loop!
- If nLoop = 1 Then Exit For
-
- ' Delay between undrawing. Change multiplier for greater delay. Note
- ' that '&' is used to prevent integer overflow here.
- For lDelayCount = 0 To NUM_DELAY * 6&
- Next
-
- Next
-
- ' Now draw the exploding rectangles.
-
- Dim nStartX As Integer
- Dim nStartY As Integer
- Dim nXInc As Integer
- Dim nYInc As Integer
- Dim nInnerLoop As Integer
-
- ' Start exploding from the center of the rectangle.
- nStartX = nWindowWidth / 2
- nStartY = nWindowHeight / 2
-
- ' Work out how many pels to an explode 'explode step'.
- nXInc = (nWindowWidth / NUM_STEPS) / 2
- nYInc = (nWindowHeight / NUM_STEPS) / 2
-
- ' Set begining position (center form).
- tNewPos.Left = tNewPos.Left + nStartX
- tNewPos.Top = tNewPos.Top + nStartY
- tNewPos.Right = tNewPos.Left + 0
- tNewPos.Bottom = tNewPos.Top + 0
-
- ' Do the 'inner' explosion.
- For nLoop = 1 To NUM_STEPS
-
- ' Adjust rect.
- InflateRect tNewPos, nXInc, nYInc
-
- ' Draw some focus rectangles.
- DrawFocusRect hDCScreen, tNewPos
-
- ' Delay between undrawing. Change multiplier for greater delay. Note
- ' that '&' is used to prevent integer overflow here.
- For lDelayCount = 0 To NUM_DELAY * 2&
- Next
-
- ' Un-draw the rectangle.
- DrawFocusRect hDCScreen, tNewPos
-
- Next
-
- g_vDummy = ReleaseDC(0, hDCScreen)
-
-
- ' ========== Code Ends .==========
-
- Exit Sub
-
- ' Error handler
- Error_TMSExplodeForm:
-
- ' Call general error handler
-
- ErrorHandler "BLOWUP.BAS/TMSExplodeForm", Err, Error$
-
- ' Default resume behaviour: exit this sub/func
-
- Resume Exit_TMSExplodeForm:
-
- Exit_TMSExplodeForm:
-
-
- End Sub
-
-